﻿Imports System.Windows.Forms

Public Class TwitterPost

    Private _image As String

    Public Property Message() As String
        Get
            Return TextBox1.Text
        End Get
        Set(ByVal value As String)
            TextBox1.Text = value
        End Set
    End Property

    Public Property Username() As String
        Get
            Return TextBox2.Text
        End Get
        Set(ByVal value As String)
            TextBox2.Text = value
        End Set
    End Property

    Public Property Password() As String
        Get
            Return TextBox3.Text
        End Get
        Set(ByVal value As String)
            TextBox3.Text = value
        End Set
    End Property

    Public Property Image() As String
        Get
            Return _image
        End Get
        Set(ByVal value As String)
            Try
                PictureBox1.Image = Drawing.Image.FromFile(value)
                _image = value
            Catch ex As Exception

            End Try
        End Set
    End Property

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Dim twitter As New Twitter.PhotoPoster
        twitter.Password = TextBox3.Text
        twitter.Username = TextBox2.Text
        twitter.UploadPhoto(Me.Image, TextBox1.Text)

        If CheckBox1.Checked = True Then
            My.Settings.username = TextBox2.Text
            My.Settings.password = TextBox3.Text
            My.Settings.Save()
        Else
            If Not My.Settings.username = "" Then
                My.Settings.username = ""
                My.Settings.password = ""
                My.Settings.Save()
            End If
        End If
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim charcount As Integer = 130 - TextBox1.Text.Length
        Label2.Text = "You can write " & charcount & " more letters"
    End Sub

    Private Sub TwitterPost_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TextBox2.Text = My.Settings.username
        TextBox3.Text = My.Settings.password
        If Not My.Settings.username = "" Then
            CheckBox1.Checked = True
        End If
    End Sub
End Class
